// SubjectInfoDialog.h
#ifndef SUBJECTINFODIALOG_H
#define SUBJECTINFODIALOG_H

#include <QDialog>
#include <QLineEdit>
#include <QComboBox>
#include <QSpinBox>
#include <QPushButton>
#include <QTextEdit>
#include <QLabel>
#include <QMap>
#include <QDateEdit>
#include <QCheckBox>
#include <QDoubleSpinBox>
#include <QTabWidget>
#include <QRadioButton>
#include <QButtonGroup>
#include "TextToSpeechManager.h"
#include "DatabaseManager.h"

class SubjectInfoDialog : public QDialog {
    Q_OBJECT
public:
    explicit SubjectInfoDialog(DatabaseManager *dbManager, QWidget *parent = nullptr);
    ~SubjectInfoDialog();

signals:
    // 当被试信息采集完成时发出信号
    void subjectInfoCollected(int subjectId);

private slots:
    void onSubmitButtonClicked();
    void onTtsStateChanged(QTextToSpeech::State state);
    void playWelcomeMessage();
    void onEducationLevelChanged(int index);
    void onMaritalStatusChanged(int index);
    void updateBMI();

private:
    // 基本信息UI元素
    QLineEdit *m_nameEdit;
    QComboBox *m_genderCombo;
    QSpinBox *m_ageSpinBox;

    // 扩展信息UI元素
    QComboBox *m_residenceTypeCombo;
    QLineEdit *m_provinceEdit;
    QLineEdit *m_cityEdit;
    QLineEdit *m_ethnicityEdit;

    // 社会学信息UI元素
    QComboBox *m_educationCombo;
    QLineEdit *m_majorEdit;
    QComboBox *m_maritalStatusCombo;
    QSpinBox *m_childrenSpinBox;
    QTextEdit *m_occupationEdit;
    QComboBox *m_incomeCombo;
    QComboBox *m_socialClassCombo;
    QSpinBox *m_familyMembersSpinBox;

    // 健康信息UI元素
    QTextEdit *m_medicalHistoryEdit;
    QTextEdit *m_medicationEdit;
    QTextEdit *m_sleepInfoEdit;
    QTextEdit *m_stressInfoEdit;
    QButtonGroup *m_smokerGroup;
    QRadioButton *m_smokerYes;
    QRadioButton *m_smokerNo;
    QButtonGroup *m_drinkerGroup;
    QRadioButton *m_drinkerYes;
    QRadioButton *m_drinkerNo;
    QButtonGroup *m_myopiaGroup;
    QRadioButton *m_myopiaYes;
    QRadioButton *m_myopiaNo;
    QSpinBox *m_sleepHoursSpinBox;
    QComboBox *m_physicalHealthCombo;
    QComboBox *m_mentalHealthCombo;
    QComboBox *m_exerciseFrequencyCombo;
    QDoubleSpinBox *m_heightSpinBox;
    QDoubleSpinBox *m_weightSpinBox;
    QLabel *m_bmiLabel;

    // 个人特质UI元素
    QComboBox *m_mbtiCombo;
    QButtonGroup *m_leftHandedGroup;
    QRadioButton *m_leftHandedYes;
    QRadioButton *m_leftHandedNo;
    QTextEdit *m_hobbiesEdit;

    // 社会关系UI元素
    QComboBox *m_socialMediaUsageCombo;
    QSpinBox *m_socialNetworkSizeSpinBox;
    QComboBox *m_communityInvolvementCombo;

    // 文化与价值观UI元素
    QComboBox *m_religionCombo;
    QComboBox *m_politicalOrientationCombo;
    QComboBox *m_languageUsageCombo;
    QComboBox *m_lifeSatisfactionCombo;
    QComboBox *m_socialConcernCombo;
    QComboBox *m_coreValuesCombo;

    // 选项卡控件
    QTabWidget *m_tabWidget;

    // 其他UI元素
    QPushButton *m_submitButton;
    QLabel *m_statusLabel;

    // 文字转语音管理器
    TextToSpeechManager *m_ttsManager;

    // 数据库管理器
    DatabaseManager *m_dbManager;

    // 欢迎提示文本
    QString m_welcomeText;

    void setupUi();
    void setupBasicInfoTab(QWidget *tab);
    void setupExtendedInfoTab(QWidget *tab);
    void setupSocialInfoTab(QWidget *tab);
    void setupHealthInfoTab(QWidget *tab);
    void setupPersonalityTab(QWidget *tab);
    void setupSocialRelationsTab(QWidget *tab);
    void setupCultureValuesTab(QWidget *tab);
    void connectSignals();
    QMap<QString, QString> collectOptionalData();
};

#endif // SUBJECTINFODIALOG_H
